package main

import (
	"crypto/rand"
	"fmt"
	"os"
	"strconv"
)

const BINARY_PATH = "binary"

func die(a ...interface{}) {
	fmt.Println(a...)
	os.Exit(127)
}

func getSize() int {
	size := 1024

	if len(os.Args) != 2 {
		return size
	}

	selfSize, err := strconv.Atoi(os.Args[1])
	if err != nil {
		return size
	}

	size = selfSize * size

	return size
}

func main() {
	size := getSize()

	os.Remove(BINARY_PATH)

	f, err := os.OpenFile(BINARY_PATH, os.O_CREATE|os.O_RDWR, 0755)
	if err != nil {
		die(err)
	}
	defer f.Close()

	b := make([]byte, 1*1024)
	rand.Read(b)

	for n := 0; n < size; n++ {
		rand.Read(b)
		f.Write(b)
	}

	fmt.Printf("Complete wite %d bytes to file!\n", size)
}
